package com.miyake.client.community;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.miyake.client.tools.ImageList;
import com.miyake.client.tools.ImageListElement;

abstract public class PublicCommunityList extends ImageList {
	
	@Override
	protected void getList() {
		service.getAllCommunityList(CommunityProperty.COMMUNITY_PUBLIC, new AsyncCallback<List<CommunityProperty>>() {
			@Override
			public void onFailure(Throwable caught) {
			}

			@Override
			public void onSuccess(List<CommunityProperty> result) {
				List<ImageListElement> e = new ArrayList<ImageListElement>();
				for (CommunityProperty c : result) {
					e.add(c);
				}
				showList(e, 8);
			}
		});
	}
	
	@Override
	protected void createCommuniy(String text, final VerticalPanel verticalPanel) {
		service.createCommunity(text, CommunityProperty.COMMUNITY_PUBLIC, new AsyncCallback<String>() {
			@Override
			public void onFailure(Throwable caught) {
			}

			@Override
			public void onSuccess(String result) {
				getList();
			}
		});
	}
	
	@Override
	protected String getCommunityTitle() {
		return "Public Community";
	}

}
